import comm from "comm";
cc.Class({
    extends: comm,

    properties: {
        time:0,
        count:0,
        tianxiangName:cc.Label,
        slider:cc.Slider,
        tiainxiangDetailNode:cc.Node,
    },

    onLoad(){
        G_wuxingfenghuolu.tianxiangObj = this; 
        this.tiainxiangDetailNode.active = false;
        this.changeTianxiang();   
    },

    openDetail(){
        this.tiainxiangDetailNode.active = !this.tiainxiangDetailNode.active;
    },

    closeTianxiang(){
        this.tiainxiangDetailNode.active = false;
    },

    changeBtnAction(){
        if(G_wuxingfenghuolu.userInfo.zuanshi<50){
            this.gameHit("钻石不足");
            return;
        }
        G_wuxingfenghuolu.userInfo.zuanshi-=50;
        G_wuxingfenghuolu.gameObj.huobiRef();
        this.changeTianxiang();
        this.saveData();
    },

    changeTianxiang(){
        var arr = Object.keys(G_wuxingfenghuolu.configJson.tianxiang);
        var r = this.random(0, arr.length-1);
        this.tianxiangName.string = arr[r];
        var data = G_wuxingfenghuolu.configJson.tianxiang[""+arr[r]];
        this.tiainxiangDetailNode.getChildByName("buff2").active = data.buff2!=""
        this.tiainxiangDetailNode.getChildByName("buff1").getComponent(cc.Label).string = "buff1:"+data.buff1;
        this.tiainxiangDetailNode.getChildByName("buff2").getComponent(cc.Label).string = "buff2:"+data.buff2;
        this.tiainxiangDetailNode.getChildByName("debuff").getComponent(cc.Label).string = "debuff:"+data.debuff;
       
    },

    update(dt){
        this.time+=dt;
        if(this.time>0.1){
            this.time = 0;
            this.count+=0.1;
            this.slider.progress = this.count/10;
            if(this.slider.progress>=1){
                this.slider.progress = 0;
                this.count = 0;
                this.changeTianxiang();
            }
        }
    }

});
